package com.ldq.imooc.basics.io;

import java.io.*;

/**
 * @Author : 李道泉
 * @Description :字符流输入输出转换
 * @Date : 2018/4/17 14:23
 * @Modified by :
 */
public class IsrAndOswDemo {

    public static void main(String[] args) throws IOException {

        FileInputStream in = new FileInputStream("F:\\IO\\io.txt");
        //默认编码方式GBK，其它格式需指定
        InputStreamReader isr = new InputStreamReader(in);

        FileOutputStream out = new FileOutputStream("F:\\IO\\io1.txt");
        OutputStreamWriter osw = new OutputStreamWriter(out,"utf-8");
//        int c;
//        while ((c = isr.read()) != -1) {
//
//            System.out.print((char) c);
//        }
        char[] buffer = new char[8 * 1024];
        int c;
        //批量读取，方人员buffer数组，从第0个位置开始放，最多放buffer.length个
        while ((c = isr.read(buffer, 0, buffer.length)) != -1) {

            String s = new String(buffer,0,c);
            System.out.print(s);

            osw.write(buffer,0,c);
            osw.flush();
        }
        isr.close();
        osw.close();
    }
}
